package Controllers;

import java.rmi.RemoteException;

import Common.Helper;
import Models.ChessPieceModel;
import Models.Point2D;
import Models.StandardChessPieceModel;

public class RookController implements ChessPieceControllerInterface {
	

	@Override
	public boolean legalMove(Point2D moveVector, ChessPieceModel chessPiece) throws RemoteException {
		if (moveVector.getX() == 0 ) {
			return true;
		}
		else if (moveVector.getY() == 0) {
			return true;
		}
		else {
		return false;
		}
	}




	@Override
	public boolean legalCapture(Point2D moveVector, ChessPieceModel chessPiece) throws RemoteException {
		// TODO Auto-generated method stub
		return legalMove(moveVector, chessPiece);
	}

	@Override
	public boolean canPieceMoveNotify(Point2D from, Point2D to,
			ChessPieceModel chessPiece) throws RemoteException {
		return legalMove(Helper.calculateVector(from, to), chessPiece);
		}
		
		
		public static ChessPieceModel getNew() throws RemoteException {
			ChessPieceModel rook = new StandardChessPieceModel();
			ChessPieceControllerInterface rookController = new RookController();
			rook.addCanPieceMoveListener(rookController);
			return rook;
		}
}
